package com.flynn.rock.system.api;

import com.flynn.rock.system.model.dto.SaveUserDto;
import com.flynn.rock.system.model.vo.UserIdVo;
import com.flynn.rock.system.service.SysUserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class SysUserApi implements ISysUserApi {

    @Resource
    private SysUserService sysUserService;

    @Override
    public UserIdVo saveUser(SaveUserDto saveUser) {
        sysUserService.getUserByPhone(saveUser.getPhone()).ifPresent(exist -> {
            if (!exist.getUserId().equals(saveUser.getUserId())) {
                throw new RuntimeException("手机号已经注册过");
            }
        });
        return sysUserService.saveUser(saveUser);
    }

    @Override
    public void deleteUser(Long userId) {
        sysUserService.deleteUser(userId);
    }
}
